<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ page isELIgnored="false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
  <head>
    <link href="<s:url value="/resources"/>/css/style_new.css" rel="stylesheet" type="text/css" />
    <link href="<s:url value="/resources"/>/css/main_new.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script> 
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/grid.locale-cn.js"></script>    
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.alerts.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/jquery.alerts.css" />
    <style>
		html, body {
			margin: 0;			 
			padding: 0;
		    font-size: 85%;
		}
	</style>
  </head>
  
  <script type="text/javascript"> 
  
   var qieye = 0; 
   $(function(){ 
	    $( "#datepicker" ).datepicker({dateFormat:'yy-mm'});
	    $( "#datepicker1" ).datepicker({dateFormat:'yy-mm'});
	    loadTab(0);
	    $( "#tabs" ).tabs({
		    select: function(event, ui) {
		    var i =ui.index;	    
		    if(i==''){
		    i="0";
		    }
		    qieye = i;
		    loadTab(i);
  		  }
	    });  
  });
  
  
  function loadTab(i){
    //重新加载列表
    $("#myTab"+i).jqGrid({      
		    url:'<s:url value="/hwjs"/>/findHwjfGrid?zhuangt='+i,   
		    datatype: 'json',
		    mtype: 'post',         
		   	colNames:['操作','合同编号','买受人','发货单位','发站','收货单位','到站','单价','交收量','货款','状态','交收月份'],
		   	colModel:[
		      	{name:'caoz',index:'sysid',width:60,align:"center"}, 
		   		{name:'hetbh',index:'hetbh',width:120},
		   		{name:'maishr',index:'maishr'},
		   		{name:'fahdw',index:'fahdw'},		
		   		{name:'fazhmc',index:'fazhmc',width:50},		
		   		{name:'shouhdw',index:'shouhdw'}, 
		   		{name:'daozhmc',index:'daozhmc',width:50},
		   		{name:'zhixdj',index:'zhixdj',width:50},
		   		{name:'jiaoshl',index:'jiaoshl',width:50},		
		   		{name:'yingfhk',index:'yingfhk',width:50},	
		   		{name:'danjzht',index:'danjzht',width:50},		
		   		{name:'jiaoshyf',index:'jiaoshyf',width:50},
		   	],
		    jsonReader: {
		           repeatitems : false, 
		           id: 'sysid'
		         },   
		    height:250, 
		    width: 1070, 	
		   	rowNum:10,
		   	rowList:[10,30,50],     	
		   	pager: '#pager'+i, 
		   	rownumbers: true,   	 
		    viewrecords: true,
		    multiselect : true,
		    sortorder: 'desc', 
		    caption: "货物交收单",
			gridComplete:function()
				{ //在此事件中循环为每一行添加修改和删除链接 	
					var ids=$("#myTab"+i).jqGrid('getDataIDs'); 
					//alert(ids);
					for(var j=0; j<ids.length; j++)
					{		
					     id=ids[j];	
					     if(i==0)	
					     {
					         caoz="<a href='#' style='color:#f60' onclick='chak("+ id +")'>查看</a>&nbsp;|&nbsp;" +
						          "<a href='#' style='color:#f60' onclick='bianj("+ id +");'>编辑</a>&nbsp;";
						      $("#myTab"+i).jqGrid('setRowData',id, { caoz: caoz }); 
					     }
					      if(i==1)	
					     {
					         caoz="<a href='#' style='color:#f60' onclick='chak("+ id +")'>查看</a>";
						     $("#myTab"+i).jqGrid('setRowData',id, { caoz: caoz }); 
					     }  
					      if(i==2)	
					     {
					         caoz="<a href='#' style='color:#f60' onclick='chak("+ id +")'>查看</a>&nbsp;";
						     $("#myTab"+i).jqGrid('setRowData',id, { caoz: caoz }); 
					     }      
					}
				} 	
		  }).trigger("reloadGrid");
		   //全部隐藏可选按钮
		  $("#shanc").hide();
	      $("#tij").hide(); 
		  $("#chex").hide();   
		   //显示按钮
		   if(i==0)
		     {
		         $("#shanc").show(); 
		         $("#tij").show(); 
		     }
		   if(i==1)
		     {
		          $("#chex").show(); 
		     }
         }
  
	   //批量删除
		function batchremove() {	
			var sysid = $("#myTab0").jqGrid('getGridParam','selarrrow');
			if (sysid.length == 0)
			{
			    jAlert('请至少选择一条记录','提示');
			}
			else
			{
			var url = "<s:url value="/hwjs"/>/removeHwjfBatch?sysid="+sysid;
			$( "#dialog-confirm" ).dialog({
					resizable: false,
					height:140,
					modal: true,
					buttons: {
						"确认": function() {
							$.post(url, function(data) {
								var obj = eval('(' + data + ')');
								if(obj.success==true){
								        //location.href ="<s:url value="/hwjs"/>/directHwjflr";
								        loadTab(qieye);
								 }else{
								         alert(obj.msg);
								       }
		                   });
		                   $( this ).dialog( "close" ); 
						},
						"返回": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			}
		}
		
		//批量提交
		function batchtij() {	
			var sysid = $("#myTab0").jqGrid('getGridParam','selarrrow');
			if (sysid.length == 0)
			{
			    jAlert('请至少选择一条记录','提示');
			}
			else
			{
			var url = "<s:url value="/hwjs"/>/tijHwjsBatch?sysid="+sysid;
			$( "#dialog-confirm1" ).dialog({
					resizable: false,
					height:140,
					modal: true,
					buttons: {
						"确认": function() {
							$.post(url, function(data) {
								var obj = eval('(' + data + ')');
								if(obj.success==true){
								        //location.href ="<s:url value="/hwjs"/>/directHwjflr";
								        loadTab(qieye);
								 }else{
								         alert(obj.msg);
								       }
		                   });
		                   $( this ).dialog( "close" ); 
						},
						"返回": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			}
		}
		
		
		//批量撤销
		function batchchex() {	
			var sysid = $("#myTab1").jqGrid('getGridParam','selarrrow');
			if (sysid.length == 0)
			{
			    jAlert('请至少选择一条记录','提示');
			}
			else
			{
			var url = "<s:url value="/hwjs"/>/chexHwjsBatch?sysid="+sysid;
			$( "#dialog-confirm1" ).dialog({
					resizable: false,
					height:140,
					modal: true,
					buttons: {
						"确认": function() {
							$.post(url, function(data) {
								var obj = eval('(' + data + ')');
								if(obj.success==true){
								        //location.href ="<s:url value="/hwjs"/>/directHwjflr";
								        loadTab(qieye);
								 }else{
								         alert(obj.msg);
								       }
		                   });
		                   $( this ).dialog( "close" ); 
						},
						"返回": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			}
		}
  
	// 查询
	function search(){ 
	  var formdata = $("#form1").serialize(); 
	  $("#myTab"+qieye).jqGrid('setGridParam',{   
					                          url:'<s:url value="/hwjs"/>/findHwjfGrid?'+ formdata +'&zhuangt='+qieye,
											  mtype:'post',
											  page:1
							              }).trigger("reloadGrid");  
	}
	
	//重置
	function resetSearch() {
		$('#list_search  input[type=text]').val('');
		$('#list_search select').val('-1');
	}

    //打开新增页面
    function opennew() { 
	    window.location.href='<s:url value="/views/hwjs/hwjf"/>/hwjflr_add.jsp',target='mainFrame';
	}
	
	
	//查看
	function chak(id) { 
	    window.location.href='<s:url value="/hwjs"/>/chakHwjs?sysid='+ id;
	}
	
	
	//修改
	function bianj(id) { //单击修改链接的操作
	/* //alert(id); 
	if(id.id!=undefined){
	window.location.href='<s:url value="/jydz"/>/editHttk?mobbm='+ id.id;
	}else{
	var mobbm = id.item(1).cells.item(1).innerHTML;
		window.location.href='<s:url value="/jydz"/>/editHttk?mobbm='+ mobbm;
	} */
	window.location.href='<s:url value="/hwjs"/>/bianjHwjs?sysid='+ id;
	}
	
	//excel
	function exportexcel(){ 
	  var formdata = $("#form1").serialize(); 
	  window.location.href("<s:url value="/hwjs"/>/excelForHwjs?"+formdata +'&zhuangt='+qieye);
	
	}
	
	

</script>  
<body>  
<div class="container">
 <div class="containerbox">
  <div class="btn-bar"> 
    <a id="xinz" href="#" class="btn" onclick= "opennew();"><img src="<s:url value="/resources"/>/img/ico_23.gif" /><span>新增</span></a> 
    <a id="shanc" href="#" class="btn" onclick="batchremove();"><img src="<s:url value="/resources"/>/img/ico_25.gif" /><span>删除</span></a>
    <a id="tij" href="#" class="btn" onclick="batchtij();"><img src="<s:url value="/resources"/>/img/operate_pass.gif" /><span>提交</span></a> 
    <a id="chex" href="#" class="btn" onclick="batchchex();"><img src="<s:url value="/resources"/>/img/operate_cancel.gif" /><span>撤销</span></a>
    <a id="excel" href="#" class="btn" onclick="exportexcel();"><img src="<s:url value="/resources"/>/img/25.gif" /> <span>导出excel</span></a>
   </div>
 <div class="search mt10" id="list_search">
<form id="form1" method="post">
<table  class="search-table"  style="width:90%"  cellpadding="0" cellspacing="0" border="0"> 
        <tr>
            <td>
            	合同号:
            </td>
            <td>
            	<input type="text" class="form-textbox" style="width: 200px;" name="aa" /> 
            </td>
            <td>
                                                  出卖人:
            </td>
            <td>
            	<input type="text" class="form-textbox" style="width: 200px;" name="bb" /> 
            </td>            
            <td>
               	买受人 :
            </td>
            <td>
                <input type="text" class="form-textbox" style="width: 200px;" name="cc" /> 
            </td>
        </tr>
        <tr>
            <td>
            	收货单位:
            </td>
            <td>
            	<input type="text" class="form-textbox" style="width: 200px;" name="dd" /> 
            </td>
            <td>
                                                  发货单位:
            </td>
            <td>
            	<input type="text" class="form-textbox" style="width: 200px;" name="ee" /> 
            </td>            
            <td>
               	到站 :
            </td>
            <td>
                <input type="text" class="form-textbox" style="width: 200px;" name="ff" /> 
            </td>
        </tr>
         <tr>
            <td>
            	卖方结算单位:
            </td>
            <td>
            	<input type="text" class="form-textbox" style="width: 200px;" name="gg" /> 
            </td>
            <td>
                                                  买方结算单位:
            </td>
            <td>
            	<input type="text" class="form-textbox" style="width: 200px;" name="hh" /> 
            </td>            
            <td>
               	发站:
            </td>
            <td>
                <input type="text" class="form-textbox" style="width: 200px;" name="ii" /> 
            </td>
        </tr>
         <tr>
            <td>
            	执行单价:
            </td>
            <td>
            	<input type="text"  class="form-textbox" style="width: 93px;" name="jj" /> - <input type="text"  class="form-textbox" style="width: 93px;" name="kk" /> 
            </td>
            <td>
                                              交收量:
            </td>
            <td>
            	<input type="text"  class="form-textbox" style="width: 93px;" name="ll" /> - <input type="text"  class="form-textbox" style="width: 93px;" name="mm" />  
            </td>            
            <td>
               	应付货款:
            </td>
            <td>
                <input type="text"  class="form-textbox" style="width: 93px;" name="nn" /> - <input type="text"  class="form-textbox" style="width: 93px;" name="oo" /> 
            </td>
        </tr>
        <tr>
        	<td>
                                                交收月份:
            </td>
            <td>
            	<input id="datepicker" type="text"  class="form-textbox" style="width: 93px;" name="pp" /> - <input id="datepicker1" type="text"  class="form-textbox" style="width: 93px;" name="qq" />
            </td>
            <td class="pr10 search-table-70">
                                                单据状态：
            </td>
            <td>
            	<select name="rr" class="form-textbox" style="width: 200px;">
            	   <option value="-1">==请选择==</option>
                   <option value="0">草稿</option>
                   <option value="1">已提交</option>
                   <option value="2">已确认</option>
                 </select>
            </td>
            <td colspan="2">
               &nbsp;
             </td>
        </tr>
        <tr>
          <td>
             <input  type="button" class="form-button-query form-button" value="查询" onclick="search();"/>
             <input  type="button" class="form-button-reset form-button" value="重置"  onclick="resetSearch();"/>
          </td>
        </tr>
  </table>
  </form>
  </div> 
    <div id="tabs">
			<ul>
				<li><a href="#tabs-0">草稿</a></li>
				<li><a href="#tabs-1">已提交</a></li>
				<li><a href="#tabs-2">已确认</a></li>
			</ul>
			<div id="tabs-0">
				<table id="myTab0" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager0" class="scroll"></div>
				<div id="message0" class="scroll"></div>
			</div>
			<div id="tabs-1">
				<table id="myTab1" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager1" class="scroll"></div>
				<div id="message1" class="scroll"></div>
			</div>
            <div id="tabs-2">
				<table id="myTab2" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager2" class="scroll"></div>
				<div id="message2" class="scroll"></div>
			</div>
     </div>
 </div>
</div> 
<div id="dialog-confirm" title="是否确认提交？"></div>
<div id="dialog-confirm1" title="是否确认提报？"></div>
<div id="dialog-confirm2" title="是否确认撤销？"></div>
</body>
</html>
